<?php
namespace Admin\Controller;
use Think\Controller;
class RoleController extends CommonController{
  /**
     * 后台导航
     *
     * @return void
     * @author 
     **/
    function add()
    {        
        if(IS_POST){

          $_POST['rules'] = implode(',',$_POST['rules']); //把数组转换成字符串

            $data =  $this->Model->data($_POST)->add(); 

            if($data){
                 $this->success('添加成功',(U('role/lists')),2);die;  
            }else{
                $this->error('添加失败','',2);die; 
            }
         }
         //查询所有顶级权限模块
       $top_rule = D('rule')->where('pid=0')->select();
       //查询子级模块
       $chind_rule = D('rule')->where('pid!=0')->select();

       $this->assign('chind_rule',$chind_rule);
       $this->assign('top_rule',$top_rule);
       $this->display();
      
       }  
       /**
        * undocumented function
        *
        * @return void
        * @author 
        **/
       function lists()
       { 
       //查询所有顶级权限模块
       $lists = $this->Model->select();
      
       $this->assign('lists',$lists);
       $this->display();
       }
}
 